package com.xiejr.config;

import cn.hutool.core.util.StrUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @program: fasttm
 * @description:
 * @author: xjr
 * @create: 2020-12-23 16:20
 **/
@Component
public class ParamConvert implements Converter<String, LocalDateTime> {
    @Override
    public LocalDateTime convert(String s) {
        if (StrUtil.isBlank(s)){
            return null;
        }
        Date date=new Date(Long.parseLong(s));
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        return instant.atZone(zoneId).toLocalDateTime();
    }
}
